/**
 * Created by Elsa on 2017/9/5.
 */

layui.define(['form', 'layedit', 'laydate','jquery'], function(exports){
    var form = layui.form(),
        $ = layui.jquery,
        layer = layui.layer,
        layedit = layui.layedit,
        laydate = layui.laydate;

    var lognum = getQueryString("inspnum");
    console.log(lognum);

    form.render();

    form.on('submit(casegly)', function(data) {
        $('input[name="logname"]').attr("disabled",false);
        $('input[name="logname"]').attr("class","layui-input");
        $('input[name="address"]').attr("disabled",false);
        $('input[name="address"]').attr("class","layui-input");
        $('textarea').attr("disabled",false);
        $('textarea').attr("class","layui-textarea");

        $('#subbit').show();
        $('#eddit').hide();
        return false;
    });

    //监听提交
    form.on('submit(caseglyx)', function(data) {
        $(this).attr('disabled','disabled');
        var ConstDetailsLog = new Object();
        ConstDetailsLog.lognum = lognum;
        ConstDetailsLog.logname = data.field.logname;
        ConstDetailsLog.ycsname = data.field.ycsname;
        ConstDetailsLog.insptype = data.field.insptype;
        ConstDetailsLog.address = data.field.address;
        ConstDetailsLog.logtime = data.field.logtime;
        ConstDetailsLog.logcontent = data.field.logcontent;

        console.log(JSON.stringify(ConstDetailsLog));

        $.ajax({
            type:"PUT",
            url:contextPath+"/project/const/log/update",
            contentType: "application/json; charset=utf-8",
            data:JSON.stringify(ConstDetailsLog),
            dataType:"json",
            success:function (data) {
                console.log(data.message);
                if(data.message == "日志更新成功!"){
                    layer.msg('日志更新成功!<br>页面将在1秒后刷新...');
                    setTimeout(function(){window.location.reload();},1000);
                } else {
                    $('#suresubmitx').attr('disabled',false);
                    layer.msg(data.message, {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }
            },
            error:function (e) {
            }
        });
        return false;
    });

    exports('ConstDetailsLog', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});